package top.zuli.package02.homework14;

public class AccountTest5 {
    public static void main(String[] args) {
        Runnable runnable = new Account5();
        Thread t1 = new Thread(runnable);
        Thread t2 = new Thread(runnable);
        t1.start();
        t2.start();
    }
}
class Account5 implements Runnable{
    private int money = 0;
    @Override
    public void run() {
        for (int i = 1; i <=3; i++) {
            show();
        }
    }
    public synchronized void show(){
        if(money < 3000){
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            money += 1000;
            System.out.println(Thread.currentThread().getName()+"：存钱成功。余额为："+money);
        }
    }
}
